package com.atguigu.gmall.seckill.rpc;


import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.activity.SeckillGoods;
import com.atguigu.gmall.seckill.service.SeckillCacheService;
import com.atguigu.gmall.seckill.service.SeckillGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RequestMapping("/api/inner/seckill")
@RestController
public class SeckillRpcController {


    @Autowired
    SeckillGoodsService seckillGoodsService;

    @Autowired
    SeckillCacheService seckillCacheService;



    //获取当天参与秒杀的商品
    @GetMapping("/today/goods")
    public Result<List<SeckillGoods>> getTodaySeckillGoods(){

        //1、查询当天参与秒杀的所有商品
        List<SeckillGoods> goods = seckillGoodsService.getTodaySeckillGoods();
        return Result.ok(goods);
    }


    @GetMapping("/goods/detail/{skuId}")
    public Result<SeckillGoods> getSeckillGoodsDetail(@PathVariable("skuId") Long skuId){
        SeckillGoods seckillGoods = seckillCacheService.getGoodsDetail(skuId);


        return Result.ok(seckillGoods);
    }





}
